<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>【新闻详情】 - RFID幼儿园无源手环</title>
    <link rel="stylesheet" href="style.css">
    <style>
        /* 新闻详情页专属样式 */
        .news-detail-page {
            margin-top: 80px; /* 避开导航栏 */
            padding: 40px 0;
        }

        .news-detail-container {
            background-color: #FFFFFF;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }

        .detail-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .detail-title {
            font-size: 26px;
            color: #333333;
            margin-bottom: 15px;
        }

        .detail-meta {
            font-size: 14px;
            color: #999999;
        }

        .detail-meta span {
            margin: 0 10px;
        }
        
        .detail-category {
            display: inline-block;
            background-color: #E8F5E9;
            color: #4CAF50;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
        }

        .detail-content {
            font-size: 16px;
            color: #666666;
            line-height: 2;
        }

        .detail-content p {
            margin-bottom: 25px;
            text-indent: 2em; 
        }

        .detail-content img {
            max-width: 100%;
            border-radius: 8px;
            margin: 20px auto;
            display: block; /* 图片居中 */
        }

        .detail-content strong {
            color: #333333;
        }
        
        .detail-tags {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #E8E8E8;
        }
        
        .tag {
            display: inline-block;
            background-color: #F5F5F5;
            color: #666;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            margin-right: 8px;
            margin-bottom: 8px;
        }

        /* 相关新闻 */
        .related-news {
            margin-top: 50px;
        }

        .related-title {
            font-size: 20px;
            color: #333333;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #E8E8E8;
        }

        .related-list {
            display: flex;
            gap: 20px;
        }

        .related-item {
            width: 33%;
            background-color: #FFFFFF;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
            transition: transform 0.3s;
        }
        
        .related-item:hover {
            transform: translateY(-3px);
        }

        .related-item h4 {
            font-size: 16px;
            margin-bottom: 10px;
        }

        .related-item h4 a {
            text-decoration: none;
            color: #333333;
            transition: color 0.3s;
        }

        .related-item h4 a:hover {
            color: #4CAF50;
        }

        .related-date {
            font-size: 12px;
            color: #999999;
            margin-bottom: 10px;
        }

        .related-excerpt {
            font-size: 14px;
            color: #666666;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        .back-to-list {
            display: inline-block;
            margin-top: 30px;
            color: #4CAF50;
            text-decoration: none;
            font-size: 14px;
        }
        
        .back-to-list:hover {
            text-decoration: underline;
        }

        /* 响应式适配 */
        @media (max-width: 768px) {
            .news-detail-container {
                padding: 20px;
            }
            .detail-title {
                font-size: 22px;
            }
            .related-list {
                flex-direction: column;
            }
            .related-item {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
        <div class="nav-container">
            <nav class="nav">
                <div class="logo">RFID无源手环</div>
                
                <!-- 汉堡菜单按钮 -->
                <div class="hamburger" id="hamburger">
                    <span></span>
                    <span></span>
                    <span></span>
                </div>
                
                <!-- 导航菜单 -->
                <ul class="nav-menu" id="navMenu">
                    <li><a href="index.html">首页</a></li>
                    <li><a href="product.html">产品介绍</a></li>
                    <li><a href="news.html">最新新闻</a></li>
                    <li><a href="about.html">关于我们</a></li>
                    <li><a href="contact.html">联系我们</a></li>
                </ul>
            </nav>
        </div>

    <!-- 新闻详情主体 -->
    <div class="news-detail-page">
        <div class="container">
            <div class="news-detail-container" id="newsDetailContainer">
                <!-- 新闻内容将通过JavaScript动态生成 -->
            </div>

            <!-- 相关新闻推荐 -->
            <div class="related-news">
                <h3 class="related-title">相关新闻</h3>
                <div class="related-list" id="relatedList">
                    <!-- 相关新闻将通过JavaScript动态生成 -->
                </div>
            </div>
            
            <a href="news.html" class="back-to-list">← 返回新闻列表</a>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="footer-content">
            <p>项目名称：基于RFID的幼儿园健康监测物联网平台</p>
            <p>联系电话：xxxxxxxxx | 邮箱：xxxxxxxxxxxx</p>
            <p>地址：珠海市珠海科技学院 | 邮编：519000</p>
            <p>© 2024 版权所有 | 环保简约 · 科技守护幼儿健康</p>
        </div>
    </footer>

    <!-- 引入新闻数据 -->
    <script src="news-data.js"></script>
    
    <!-- 新闻详情功能脚本 -->
    <script>
        // 新闻详情页初始化
        function initNewsDetail() {
            const urlParams = new URLSearchParams(window.location.search);
            const newsId = urlParams.get('id');
            const news = allNews.find(item => item.id == newsId);
            
            if (!news) {
                document.getElementById('newsDetailContainer').innerHTML = `
                    <div style="text-align: center; padding: 60px 20px;">
                        <h2>新闻未找到</h2>
                        <p>抱歉，您查找的新闻不存在或已被删除。</p>
                        <a href="news.html" class="btn" style="margin-top: 20px;">返回新闻列表</a>
                    </div>
                `;
                document.getElementById('related-news').style.display = 'none';
                return;
            }
            
            // 更新页面标题
            document.title = `【${news.category}】${news.title} - RFID幼儿园无源手环`;
            
            // 渲染新闻内容
            document.getElementById('newsDetailContainer').innerHTML = `
                <!-- 新闻标题与元信息 -->
                <div class="detail-header">
                    <h1 class="detail-title">${news.title}</h1>
                    <div class="detail-meta">
                        <span>发布时间：${news.date}</span>
                        <span>分类：<span class="detail-category">${news.category}</span></span>
                    </div>
                </div>

                <!-- 新闻正文 -->
                <div class="detail-content">
                    ${news.content}
                </div>
                
                <!-- 标签 -->
                <div class="detail-tags">
                    ${news.tags.map(tag => `<span class="tag">#${tag}</span>`).join('')}
                </div>
            `;
            
            // 渲染相关新闻
            renderRelatedNews(newsId);
        }
        
        // 自动生成相关新闻推荐
        function renderRelatedNews(currentNewsId) {
            const currentNews = allNews.find(news => news.id == currentNewsId);
            const relatedList = document.getElementById('relatedList');
            
            if (!currentNews) return;
            
            // 基于标签相似度和类别推荐
            const relatedNews = allNews
                .filter(news => news.id != currentNewsId) // 排除当前新闻
                .map(news => {
                    // 计算相似度分数
                    let score = 0;
                    
                    // 相同类别加分
                    if (news.category === currentNews.category) {
                        score += 3;
                    }
                    
                    // 相同标签加分
                    const commonTags = news.tags.filter(tag => 
                        currentNews.tags.includes(tag)
                    ).length;
                    score += commonTags * 2;
                    
                    return { ...news, score };
                })
                .filter(news => news.score > 0) // 只保留有相关性的新闻
                .sort((a, b) => b.score - a.score) // 按相关性排序
                .slice(0, 3); // 最多推荐3条
            
            let html = '';
            
            if (relatedNews.length === 0) {
                // 如果没有相关新闻，显示最新新闻
                const latestNews = allNews
                    .filter(news => news.id != currentNewsId)
                    .sort((a, b) => new Date(b.date) - new Date(a.date))
                    .slice(0, 3);
                
                latestNews.forEach(news => {
                    html += `
                    <div class="related-item">
                        <h4><a href="news-detail.html?id=${news.id}">${news.title}</a></h4>
                        <div class="related-date">${news.date}</div>
                        <p class="related-excerpt">${news.excerpt}</p>
                    </div>
                    `;
                });
            } else {
                relatedNews.forEach(news => {
                    html += `
                    <div class="related-item">
                        <h4><a href="news-detail.html?id=${news.id}">${news.title}</a></h4>
                        <div class="related-date">${news.date}</div>
                        <p class="related-excerpt">${news.excerpt}</p>
                    </div>
                    `;
                });
            }
            
            relatedList.innerHTML = html;
        }
        
        // 初始化新闻详情页
        document.addEventListener('DOMContentLoaded', initNewsDetail);
    </script>
	<script>
	        // 汉堡菜单交互功能
	        document.addEventListener('DOMContentLoaded', function() {
	            const hamburger = document.getElementById('hamburger');
	            const navMenu = document.getElementById('navMenu');
	            
	            // 点击汉堡菜单切换导航显示
	            hamburger.addEventListener('click', function() {
	                hamburger.classList.toggle('active');
	                navMenu.classList.toggle('active');
	            });
	            
	            // 点击导航链接后关闭移动端菜单
	            const navLinks = document.querySelectorAll('.nav-menu a');
	            navLinks.forEach(link => {
	                link.addEventListener('click', function() {
	                    if (window.innerWidth <= 768) {
	                        hamburger.classList.remove('active');
	                        navMenu.classList.remove('active');
	                    }
	                });
	            });
	            
	            // 窗口大小变化时重置菜单状态
	            window.addEventListener('resize', function() {
	                if (window.innerWidth > 768) {
	                    hamburger.classList.remove('active');
	                    navMenu.classList.remove('active');
	                }
	            });
	        });
	    </script>
</body>
</html>